#!/bin/sh
#
# Incoming Slackware automated installation script
#
#   Copyright 2013 Coastal Carolina University
#   Copyright 2007 Clemson University
#
#   Licensed under the Apache License, Version 2.0 (the "License");
#   you may not use this file except in compliance with the License.
#   You may obtain a copy of the License at
#
#       http://www.apache.org/licenses/LICENSE-2.0
#
#   Unless required by applicable law or agreed to in writing, software
#   distributed under the License is distributed on an "AS IS" BASIS,
#   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#   See the License for the specific language governing permissions and
#   limitations under the License.


# Slackware automated install script
# Author: Michael Fenn

# fstab
echo "Creating fstab"

cat > /mnt/root/etc/fstab << EOF
/dev/sda2        swap             swap        defaults         0   0
/dev/sdb2        swap             swap        defaults         0   0
/dev/md1         /                ext3        defaults         1   1
devpts           /dev/pts         devpts      gid=5,mode=620   0   0
proc             /proc            proc        defaults         0   0
10.42.8.8:/home  /home            nfs         rw,vers=3        0   0
/dev/md0         /dfs             ext3        defaults         1   2
EOF


# networking
echo "Setting up networking"

# rc scripts
echo "Setting rc scripts"

chmod +x /mnt/root/etc/rc.d/rc.4*
chmod +x /mnt/root/etc/rc.d/rc.6*
chmod +x /mnt/root/etc/rc.d/rc.K*
chmod +x /mnt/root/etc/rc.d/rc.M*
chmod +x /mnt/root/etc/rc.d/rc.S*
chmod +x /mnt/root/etc/rc.d/rc.acpid*
chmod +x /mnt/root/etc/rc.d/rc.font.new*
chmod +x /mnt/root/etc/rc.d/rc.hald*
chmod +x /mnt/root/etc/rc.d/rc.inet1*
chmod +x /mnt/root/etc/rc.d/rc.inet2*
chmod +x /mnt/root/etc/rc.d/rc.inetd*
chmod +x /mnt/root/etc/rc.d/rc.local*
chmod +x /mnt/root/etc/rc.d/rc.messagebus*
chmod +x /mnt/root/etc/rc.d/rc.modules-2.6.21.5-smp*
chmod +x /mnt/root/etc/rc.d/rc.nfsd*
chmod +x /mnt/root/etc/rc.d/rc.ntpd*
chmod +x /mnt/root/etc/rc.d/rc.rpc*
chmod +x /mnt/root/etc/rc.d/rc.scanluns*
chmod +x /mnt/root/etc/rc.d/rc.sshd*
chmod +x /mnt/root/etc/rc.d/rc.syslog*
chmod +x /mnt/root/etc/rc.d/rc.sysvinit*
chmod +x /mnt/root/etc/rc.d/rc.udev*
chmod +x /mnt/root/etc/rc.d/rc.gmond*

# ganglia
echo "Setting up ganglia"

# setup ldconfig
echo "Setting up ldconfig"
chroot /mnt/root /sbin/ldconfig
chroot /mnt/root /sbin/depmod -ae

# set root password
echo "Setting root password"
# set timezone
echo "Setting up timezone"
rm -rf /mnt/root/etc/localtime
chroot /mnt/root ln -sf /usr/share/zoneinfo/America/New_York \
       /etc/localtime
echo "UTC" > /mnt/root/etc/hardwareclock

# create X11 font cache
echo "Creating X11 font cache"
chroot /mnt/root /usr/bin/fc-cache

# setup ssh keys
echo "Creating ssh keys"
chmod 600 /mnt/root/root/.ssh/id_dsa
echo "StrictHostKeyChecking no" >> /mnt/root/etc/ssh/ssh_config

# ldap config
echo "Configuring ldap"
chmod 600 /mnt/root/etc/ldap.secret

# /etc/hosts
hn=`/bin/hostname`
echo "${hn}" > /mnt/root/etc/HOSTNAME
echo "127.0.0.1		localhost ${hn}" > /mnt/root/etc/hosts

sleep 5

# grub
echo "Installing grub to MBR"

mkdir /mnt/root/boot/grub
cp /mnt/root/usr/lib/grub/i386-pc/* /mnt/root/boot/grub

/mnt/root/usr/sbin/grub << EOF
root (hd0,0)
setup (hd0)
EOF

# poweroff
echo "Powering off"
sleep 10
umount /mnt/root/dfs
umount /mnt/root
umount /mnt/pkgs
/sbin/poweroff

